<?php
    include "./init.inc.php";

    $act = empty($_GET['act']) ? "index" : $_GET['act'];

    //首页 页面
    if($act == 'index')
    {
        //获取轮播图
        if ($lan == 'zh')
        {
            $banner = $dosql->Execute("SELECT picurl,linkurl FROM `#@__admanage` WHERE `siteid`='1' and `checkinfo`='true' and `classid`='1' and picurl!='' order by orderid asc limit 5");
        }
        else
        {
            $banner = $dosql->Execute("SELECT picurl,linkurl FROM `#@__admanage` WHERE `siteid`='1' and `checkinfo`='true' and `classid`='2' and picurl!='' order by orderid asc limit 5");
        }
        while($banner = $dosql->GetArray())
        {
            $banners[] = $banner;
        }

        //获取新闻
        if ($lan == 'zh')
        {
            $new = $dosql->GetOne("SELECT id,title,picurl,description,hits,posttime FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%h%' and `picurl` !='' and `classid` ='15' and `parentid` ='3' order by orderid desc limit 1");
        }
        else
        {
            $new = $dosql->GetOne("SELECT id,title,picurl,description,hits,posttime FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%h%' and `picurl` !='' and `classid` ='16' and `parentid` ='3' order by orderid desc limit 1");
        }
        $new['posttime'] = date('Y-m-d',$new['posttime']);

        if ($lan == 'zh')
        {
            $new_list = $dosql->Execute("SELECT id,title,picurl,posttime FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%c%' and `picurl` !='' and `classid` ='15' and `parentid` ='3' order by orderid desc limit 6");
        }
        else
        {
            $new_list = $dosql->Execute("SELECT id,title,picurl,posttime FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%c%' and `picurl` !='' and `classid` ='16' and `parentid` ='3' order by orderid desc limit 6");
        }
        while($new_list = $dosql->GetArray())
        {
            $new_list['posttime'] = date('Y-m-d',$new_list['posttime']);
            $new_lists[] = $new_list;
        }

        //获取产品
        $float = 0;
        if ($lan == 'zh')
        {
            $product = $dosql->Execute("SELECT id,title,picurl,description,hits,posttime FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%h%' and `picurl` !='' and `classid` ='17' and `parentid` ='4' order by orderid desc limit 4");
        }
        else
        {
            $product = $dosql->Execute("SELECT id,title,picurl,description,hits,posttime FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `flag` LIKE '%h%' and `picurl` !='' and `classid` ='18' and `parentid` ='4' order by orderid desc limit 4");
        }
        while($product = $dosql->GetArray())
        {
            $product['posttime'] = date('Y-m-d',$product['posttime']);
            if ($float % 2)
            {
                $product['class'] = 'col-md-6 top-text two';
            }
            else
            {
                $product['class'] = 'col-md-6 top-text';
            }
            $float += 1;
            $products[] = $product;
        }
        @$products_one[] = $products[0];
        @$products_one[] = $products[1];
        @$products_two[] = $products[2];
        @$products_two[] = $products[3];

        //传入轮播图
        $smarty -> assign('banner',$banners);
        //第一个传入新闻
        $smarty -> assign('new',$new);
        //传入新闻列表
        $smarty -> assign('new_lists',$new_lists);
        //传入产品列表
        $smarty -> assign('products_one',$products_one);
        $smarty -> assign('products_two',$products_two);
        $smarty -> assign('left','1');
        $smarty->display('index.html');
    }
    //产品展示-列表页
    elseif($act == 'product_list')
    {
        if ($lan == 'zh')
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='17' and `parentid` ='4' order by orderid desc";
            $smarty -> assign('tit','产品展示');
        }
        else
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='18' and `parentid` ='4' order by orderid desc";
            $smarty -> assign('tit','PRODUCT');
        }


        $dopage->GetPage("$sql",12);
        while($row = $dosql->GetArray())
        {
            if (!$row['picurl'])
            {
                if ($lan == 'zh')
                {
                    $row['picurl'] = 'templates/images/no_zh.jpg';
                }
                else
                {
                    $row['picurl'] = 'templates/images/no_en.jpg';
                }
            }
            $products[] = $row;
        }

        $smarty -> assign('linkurl','product_show');
        $smarty -> assign('products',$products);
        $smarty->assign('page',$dopage->GetList());
        $smarty -> assign('left','2');
        $smarty->display('list.html');
    }
    //产品展示-详情页
    elseif($act == 'product_show')
    {
        $act = empty($_GET['id']) ? "" : $_GET['id'];
        if (!$act)
        {
            echo "<script>window.history.go(-1);</script>";die;
        }

        $con = $dosql->GetOne("SELECT title,content,hits,posttime FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `id`='$id' limit 1");
        if (!$con)
        {
            if ($lan == 'zh')
            {
                echo "<script>alert('没有此产品');window.history.go(-1);</script>";die;
            }
            else
            {
                echo "<script>alert('No such product');window.history.go(-1);</script>";die;
            }
        }

        if ($lan == 'zh')
        {
            $smarty -> assign('tit','产品展示');
            $con['outher'] = "发布时间：". date('Y-m-d',$con['posttime'])."&nbsp;&nbsp;点击量：". $con['hits'];
        }
        else
        {
            $smarty -> assign('tit','PRODUCT');
            $con['outher'] = "Time : ". date('Y-m-d',$con['posttime'])."&nbsp;&nbsp;Hits : ". $con['hits'];
        }

        $smarty->assign('con',$con);
        $smarty -> assign('left','2');
        $smarty->display('con_show.html');
    }
    //行业资讯-列表页
    elseif($act == 'new_list')
    {
        if ($lan == 'zh')
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='15' and `parentid` ='3' order by orderid desc";
            $smarty -> assign('tit','行业资讯');
        }
        else
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='16' and `parentid` ='3' order by orderid desc";
            $smarty -> assign('tit','INFORMATION');
        }

        $dopage->GetPage("$sql",12);
        while($row = $dosql->GetArray())
        {
            if (!$row['picurl'])
            {
                if ($lan == 'zh')
                {
                    $row['picurl'] = 'templates/images/no_zh.jpg';
                }
                else
                {
                    $row['picurl'] = 'templates/images/no_en.jpg';
                }
            }
            $products[] = $row;
        }

        $smarty -> assign('linkurl','new_show');
        $smarty -> assign('products',$products);
        $smarty->assign('page',$dopage->GetList());
        $smarty -> assign('left','3');
        $smarty->display('list.html');
    }
    //行业资讯-详情页
    elseif($act == 'new_show')
    {
        $act = empty($_GET['id']) ? "" : $_GET['id'];
        if (!$act)
        {
            echo "<script>window.history.go(-1);</script>";die;
        }

        $con = $dosql->GetOne("SELECT title,content,hits,posttime FROM `#@__infolist` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `id`='$id' limit 1");
        if (!$con)
        {
            if ($lan == 'zh')
            {
                echo "<script>alert('没有此文章');window.history.go(-1);</script>";die;
            }
            else
            {
                echo "<script>alert('No such article');window.history.go(-1);</script>";die;
            }
        }

        if ($lan == 'zh')
        {
            $smarty -> assign('tit','行业资讯');
            $con['outher'] = "发布时间：". date('Y-m-d',$con['posttime'])."&nbsp;&nbsp;点击量：". $con['hits'];
        }
        else
        {
            $smarty -> assign('tit','INFORMATION');
            $con['outher'] = "Time : ". date('Y-m-d',$con['posttime'])."&nbsp;&nbsp;Hits : ". $con['hits'];
        }

        $smarty->assign('con',$con);
        $smarty -> assign('left','3');
        $smarty->display('con_show.html');
    }
    //关于我们
    elseif($act == 'about_us')
    {
        //获取关于我们内容
        if ($lan == 'zh')
        {
            $about = $dosql->GetOne("SELECT content FROM `#@__info` WHERE id='1' and classid='1'");
            $smarty -> assign('tit','关于我们');
        }
        else
        {
            $about = $dosql->GetOne("SELECT content FROM `#@__info` WHERE id='2' and classid='2'");
            $smarty -> assign('tit','About');
        }

        //传入内容
        $smarty -> assign('content',$about);
        $smarty -> assign('left','4');
        $smarty->display('show.html');
    }
    //在线留言
    elseif($act == 'contact')
    {
        $name = empty($_POST['name']) ? "" : $_POST['name'];
        $email = empty($_POST['email']) ? "" : $_POST['email'];
        $phone = empty($_POST['phone']) ? "" : $_POST['phone'];
        $con = empty($_POST['con']) ? "" : $_POST['con'];
        $time = date('Y-m-d H:i:s');

        if($name && $email && $phone && $con)
        {
            $sql = "INSERT INTO `#@__message` (siteid, nickname, phone, content, posttime, email) VALUES ('1', '$name', '$phone', '$con', '$time', '$email')";
            if($dosql->ExecNoneQuery($sql))
            {
                if ($lan == 'zh')
                {
                    echo "<script>alert('留言成功！');self.location=document.referrer;</script>";die;
                }
                else
                {
                    echo "<script>alert('Message successfully！');self.location=document.referrer;</script>";die;
                }
            }
        }
        else
        {
            if ($lan == 'zh')
            {
                echo "<script>alert('请将信息填写完整！');window.history.go(-1);</script>";die;
            }
            else
            {
                echo "<script>alert('Please complete the information！');window.history.go(-1);</script>";die;
            }
        }
    }
    //搜索
    elseif ($act == 'search')
    {
        if(!$_POST['val'])
        {
            if ($lan == 'zh')
            {
                echo "<script>alert('请填写搜索内容！');window.history.go(-1);</script>";die;
            }
            else
            {
                echo "<script>alert('Please fill in the search content!');window.history.go(-1);</script>";die;
            }
        }

        $key = $_POST['val'];

        if ($lan == 'zh')
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='17' and `parentid` ='4' and `title` like '%$key%' order by orderid desc";
            $smarty -> assign('tit','产品展示');
        }
        else
        {
            $sql = "SELECT id,title,picurl,keywords FROM `#@__infoimg` WHERE `siteid`='1' and `checkinfo`='true' and `delstate`='' and `classid` ='18' and `parentid` ='4' and `title` like '%$key%' order by orderid desc";
            $smarty -> assign('tit','PRODUCT');
        }

        $dopage->GetPage("$sql",12);
        while($row = $dosql->GetArray())
        {
            $products[] = $row;
        }

        $smarty -> assign('linkurl','product_show');
        $smarty -> assign('products',$products);
        $smarty->assign('page',$dopage->GetList());
        $smarty -> assign('left','2');
        $smarty->display('list.html');
    }
    //语言 ajax
    elseif($act == 'lan')
    {
        $lan = empty($_POST['lan']) ? "zh" : $_POST['lan'];
        if(setcookie("wm_lan","$lan"))
        {
            echo 1;die;
        }
        else
        {
            echo 0;die;
        }
    }
    else
    {
        Header("Location: index.php?act=index");
    }
?>
